package com.zwxu.stack;

import java.util.Stack;

public class MinStackDemo {

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		 MinStack minStack=new MinStack();

		//以下测试用例
		        minStack.push(1);
		    
		        minStack.push(2);
		        minStack.pop();
		        minStack.push(3);
		        minStack.push(4);
		        minStack.pop();
		        minStack.pop();
		        System.out.print(minStack.min());

	}

}

class MinStack {
	 private Stack<Integer> myStack;
	    private Stack<Integer> supportStack;

	    public MinStack() {
	        myStack = new Stack<Integer>();
	        supportStack=new Stack<Integer>();
	    }

	    public void push(int number) {
	    	if(supportStack.empty() || number <= supportStack.peek()){
	            supportStack.push(number);
	        }else{
	            supportStack.push(supportStack.peek());
	        }
	    	myStack.push(number);
	    }

	    public int pop() {
	        supportStack.pop();
	        return myStack.pop();
	    }

	    public int min() {
	        return supportStack.peek();
	    }
}
